using System;
using System.Data;
using WP.DB;
using WP.MF.DataEntity;
using WP.Commons;

namespace WP.MF.DataAccess
{
    public class MOutLookAddinMenuHdrDAL : IDataAccess
    {
        public MOutLookAddinMenuHdrDAL()
        { 
        }
        #region Select List
        public string SQLList(int iParameter)
        {
            string strSQL = @"SELECT * From mOutLookAddinMenuHdr ORDER BY UserName ";
            return strSQL;
        }
        #endregion
        #region Fields
        private string Fields
        {
            get
            {
                return @"UserName, OutlookMenuName,ServerName,DBName";
            }
        }
        private string DtlFields
        {
            get
            {
                return @"UserName, OutlookMenuName,MenuID,MenuName";
            }
        }
        #endregion
        #region	SelectDataByRecID
        public MOutLookAddinMenuHdrDEL SelectDataByRecID(DBAccess dBAccess, string strRecId)
        {
            MOutLookAddinMenuHdrDEL mDEL = new MOutLookAddinMenuHdrDEL();
            string strSql = string.Empty;
            strSql = "SELECT " + Fields + ",RecId,RecStamp FROM mOutLookAddinMenuHdr ";
            if (strRecId != "" && int.Parse(strRecId) >= 0)
            {
                strSql += " WHERE RecId=" + strRecId;
            }
            dBAccess.GetDataSet(strSql, MOutLookAddinMenuHdrDEL.TABLENAME, mDEL);
            return mDEL;
        }
        #endregion

 
        #region update head table
        public void InsertmOutLookAddinMenuHdr(DBAccess dBAccess, MOutLookAddinMenuHdrDEL mDEL)
        {
            string strSql = string.Empty;
            DataRow dr = mDEL.Tables[0].Rows[0];
            strSql = BaseFunctions.GenerateSqlForDataAccess(Fields, MOutLookAddinMenuHdrDEL.TABLENAME, dr, FormStatus.AddNew);
            dr[MPrinterDEL.RECID] = dBAccess.GetObjectValue(strSql);
        }
        public void UpdatemOutLookAddinMenuHdr(DBAccess dBAccess, MOutLookAddinMenuHdrDEL mDEL)
        {
            string strSql = string.Empty;
            DataRow dr = mDEL.Tables[0].Rows[0];
            strSql = BaseFunctions.GenerateSqlForDataAccess(Fields, MOutLookAddinMenuHdrDEL.TABLENAME, dr, FormStatus.Update);
            dr[MPrinterDEL.RECSTAMP] = dBAccess.GetObjectValue(strSql);
        }
        public void DeletemOutLookAddinMenuHdr(DBAccess dBAccess, int iRecID)
        {
            string strSql = string.Empty;

            strSql = @"DELETE FROM mOutLookAddinMenuDtl where recid in (select a.Recid from mOutLookAddinMenuDtl a inner join mOutLookAddinMenuHdr b on a.OutlookMenuName=b.OutlookMenuName and a.UserName=b.UserName and b.RecID=" + iRecID +")";
            dBAccess.ExecuteSql(strSql);

            strSql = @"DELETE FROM mOutLookAddinMenuHdr WHERE RecID=" + iRecID;
            dBAccess.ExecuteSql(strSql);


        }
        #endregion





        #region update detail 
        public void InsertmOutLookAddinMenuDtl(DBAccess dBAccess, DataRow  dr)
        {
            string strSql = string.Empty;
            strSql = BaseFunctions.GenerateSqlForDataAccess(DtlFields, "mOutLookAddinMenuDtl", dr, FormStatus.AddNew);
            dr[MPrinterDEL.RECID] = dBAccess.GetObjectValue(strSql);
        }
        public void UpdatemOutLookAddinMenuDtl(DBAccess dBAccess, DataRow dr)
        {
            string strSql = string.Empty;
            strSql = BaseFunctions.GenerateSqlForDataAccess(DtlFields, "mOutLookAddinMenuDtl", dr, FormStatus.Update);
            dr[MPrinterDEL.RECSTAMP] = dBAccess.GetObjectValue(strSql);
        }
        public void DeletemOutLookAddinMenuDtl(DBAccess dBAccess, int iRecID)
        {
            string strSql = string.Empty;
            strSql = @"DELETE FROM mOutLookAddinMenuDtl WHERE RecID=" + iRecID;
            dBAccess.ExecuteSql(strSql);
        }
        #endregion

    }
}
